﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Customer.DAL;
using iLangl.Model;

namespace iLangl.Customer.Managers
{
	public class ProjectManager
	{
		#region Singelton Pattern
		private static ProjectManager instance;
		private static object mutex = new object();
		/// <summary>
		/// The instance of the ProjectManager.
		/// </summary>
		public static ProjectManager Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = new ProjectManager();

						}
					}
				}
				return instance;
			}
		}
		#endregion


		public void CreateProject(CustomerProject project)
		{
			DALFacade.Instance.ProjectDAL.CreateProject(project, null);

			foreach (ContentEntity content in project.Contents)
			{
				DALFacade.Instance.ContentDAL.CreateContent(content, null);
			}

			foreach (Translation translation in project.Translations)
			{
				DALFacade.Instance.TranslationDAL.CreateTranslation(translation, null);
			}
		}

		public void Update(CustomerProject project)
		{
			CreateProject(project);
		}
	}
}
